#pragma once
#include "Hashtable.h"
using namespace Su;

namespace Su
{
	template<class K, class V>
	class unordered_map
	{
	public:
		struct Mapofkey
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
		typedef typename HashTable<K, pair< K, V>, Mapofkey>::iterator iterator;
		typedef typename HashTable<K, pair< K, V>, Mapofkey>::const_iterator const_iterator;
		pair<iterator, bool> insert(const pair<K,V>& kv)
		{
			return _ht.insert(kv);
		}
		bool print()
		{
			return _ht.print();
		}
		const_iterator begin() const
		{
			return _ht.begin();
		}
		const_iterator end() const
		{
			return _ht.end();
		}
		iterator begin()
		{
			return _ht.begin();
		}
		
		iterator end()
		{
			return _ht.end();
		}
		V& operator[](const K& key)
		{
			pair<iterator, bool> it = _ht.insert(make_pair(key, V()));//传V的一个默认构造
			return it.first->second;
		}
	private:
		HashTable<K, pair<K, V>, Mapofkey> _ht;
	};
}
